package com.cloudfun.campusshare.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.cloudfun.campusshare.common.model.dto.KjtNotifyDTO;
import com.cloudfun.campusshare.entity.KjtNotifyEntity;
import com.cloudfun.campusshare.repo.KjtNotifyRepo;
import com.cloudfun.campusshare.service.KjtNotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by CodeGenerator on 2020/08/10
 */
@Slf4j
@Service
public class KjtNotifyServiceImpl implements KjtNotifyService {

    @Autowired
    private KjtNotifyRepo notifyRepo;

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void create(KjtNotifyDTO notifyDTO) {
        KjtNotifyEntity notifyEntity = notifyRepo.findByNotifyId(notifyDTO.getNotifyId());
        if (null == notifyEntity) {
            notifyEntity = new KjtNotifyEntity();
            BeanUtil.copyProperties(notifyDTO, notifyEntity);
        } else {
            BeanUtil.copyProperties(notifyDTO, notifyEntity, CopyOptions.create().setIgnoreNullValue(true));
        }
        notifyRepo.save(notifyEntity);
    }
}